<template>
  <div>
    <el-form :inline="true" :model="form" class="demo-form-inline">
      <el-form-item label="关键词">
        <el-input v-model="form.queryValue" placeholder="请输入要查询的内容"></el-input>
      </el-form-item>
      <el-form-item label="活动区域">
        <el-select v-model="form.queryKey" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="go">go</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData"
              border
              style="width: 100%">
      <el-table-column
        prop="id"
        label="ID"
        width="50">
      </el-table-column>
      <el-table-column
        prop="nickname"
        label="昵称"
        width="100">
      </el-table-column>
      <el-table-column
        prop="email"
        label="绑定的邮箱">
      </el-table-column>
      <el-table-column
        prop="mobile"
        label="手机号码">
      </el-table-column>
      <el-table-column
        prop="regisDate"
        label="注册时间">
      </el-table-column>
      <el-table-column
        prop="account"
        label="账号">
      </el-table-column>
      <el-table-column
        prop="lastLoginDate"
        label="创建的时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">修改</el-button>
          <el-button @click="deleteUser(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>


    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage1"
        :page-size="page_size"
        layout="total, prev, pager, next"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  export default {
    name: '',
    data() {
      return {
        // 表单
        form: {
          queryKey: '',
          queryValue: '',
          page: 1,
          sortType: 1
        },
        // 回显所需要的内容
        tableData: [],
        currentPage1: 1,
        total: 0,
        page_size: 10,
        // 表单所支持的查询项目
        options: [
          {
            value: 'all',
            label: '全模糊查找'
          }, {
            value: 'siteUrl',
            label: '按URL查找'
          },
          {
            value: 'siteName',
            label: '按站点名查找'
          },
          {
            value: 'accounts',
            label: '按帐号查找'
          },
          {
            value: 'password',
            label: '按密码查找'
          },
          {
            value: 'mark',
            label: '按说明查找'
          }, {
            value: 'tag',
            label: '按标签查找'
          }
        ]
      }
    },
    mounted() {
      this.loadData();
    },
    methods: {
      go() {
        this.loadData();
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(val)
        this.loadData(val);
      },
      /**
       * 加载数据
       * @param page 第几页,当page为给定时,默认值为1
       */
      loadData(page = 1) {
        this.form.page = page;
        this.$ajax.get("api", "user", "getAll", this.form).then(res => {
          if (res.data.code == 200) {
            let data = res.data.data;
            this.total = data.total;
            this.tableData = data.rows;
          } else {
            this.$message(res.data.msg);
          }
        });
      },
      handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath);
      },
      deleteUser(data) {
        console.log(data);
        this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$ajax.get("api", "user", "delete", {id: 3}).then(res => {
            if (res.code == 200) {
              if (res.data == true) {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
                return;
              }
            }
            this.$message({
              type: 'faild',
              message: '删除失败!'
            });

          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
